home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-30 | 3.6 KB | 134 lines | [TEXT/GEOL] |
- Item 2524183 27-March-90 23:30PST
-
- From: D0532 Aidea Systems, Don Park,PRT
-
- To: CPLUS.DEV$ C++ Interest List--Developers
- CPLUS.APPLE$ C++ Interest List--Apple Employees
-
- Sub: Screaming Free Store!!!
-
- Hello, folks!
-
- I have been concerned about the speed of default C++ free store mechanism, so I
- wrote my own free store mechanism which I call 'Arena'. Having written it, I
- wanted to see how it compared with other mechanisms, so I wrote a set of
- programs which simply allocates 100 integer objects 100 times. I think the
- test is a good representation of a graphics oriented application in which
- thousands objects have to be generated practically instantly to represent
- various path elements of sophisticated drawing.
-
- Following are the mechanism I have tested:
-
- 1. NewPtr/DisposPtr // Direct calls to Memory Manager
- 2. HandleObject // Deriving from HandleObject
- 3. new/delete // Standard free store mechanism
- 4. malloc/free // Direct calls to StdLib
- 5. Arena // My own mechanism
-
- Following are the results of those tests on Mac IIcx:
-
- 1. NewPtr/DisposPtr = 461 ticks
- 2. HandleObject = 128 ticks
- 3. new/delete = 109 ticks
- 4. malloc/free = 85 ticks
- 5. Arena = 15 ticks
-
- One would think that by overriding new/delete with calls to NewPtr/DisposPtr
- would increase the speed of free store object allocation, but it turns out that
- NewPtr/DisposPtr is the slowest of them all, taking over 4 times more time than
- default new/delete code. HandleObject for some reason was much better, only
- slightly slower than new/delete. Fact that NewPtr/DisposPtr takes longer than
- HandleObject is certainly strange. However it is not strange to find
- malloc/free somewhat faster than new/delete since the later uses calloc/free.
-
- Well, I am quite satisfied with the result of the test. Arena is over 7 times
- faster than the standard new/delete mechanism. I am planning to use it in few
- places where it demands nose bleeding speed.
-
- Please do not be despaired if you think you are stuck with the standard
- new/delete mechanism. I am sure you guys can also come up with your own
- mechanisms but the important thing is that you should not sit on your you know
- what and rely on the standard mechanism.
-
- Don Park
-
- P.S. Test program source follows:
-
- #if NewPtrFreeStore
-
- class IntObj
- {
- public:
- void * operator new ( size_t sz )
- {
- return NewPtr((Size)sz);
- }
- void operator delete ( void * dp )
- {
- DisposPtr((Ptr)dp);
- }
- int i;
- };
-
- #elif HandleObjectFreeStore
-
- class IntObj : HandleObject
- {
- int i;
- };
-
- #elif DefaultFreeStore
-
- class IntObj
- {
- int i;
- };
-
- #elif MallocFreeStore
-
- class IntObj
- {
- public:
- void * operator new ( size_t sz )
- {
- return (void*)malloc(sz);
- }
- void operator delete ( void * dp )
- {
- free(dp);
- }
- int i;
- };
-
- #elif ArenaFreeStore
-
- class IntObj : public AxArenaObject
- {
- int i;
- };
-
- #endif
-
- const NI = 100;
- const NJ = 100;
-
- IntObj * iobj[NJ];
-
- main ()
- {
- long tick;
- int i, j;
-
- tick = TickCount();
- for (i = 0; i < NI; i++)
- {
- for (j = 0; j < NJ; j++)
- iobj[j] = new IntObj;
- for (j = 0; j < NJ; j++)
- delete iobj[j];
- }
- tick = TickCount() - tick;
- cout << tick << '\n';
- }
-
-